<template>
  <div class="app-container">
    <el-form ref="form" :model="form" label-width="150px" style="margin-left: 50px;margin-top: 30px;width: 700px">
      <el-form-item label="出差目的地">
        <el-input v-model="form.target" placeholder="请输入出差目的地"></el-input>
      </el-form-item>
      <el-form-item label="请输入出差开始日期">
        <el-date-picker clearable
            v-model="form.startDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请输入出差开始日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="请输入出差结束日期">
        <el-date-picker clearable
            v-model="form.endDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请输入出差结束日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="请输入出差预计费用">
        <el-input-number v-model="form.cost" :min="0" :max="1000" label="请输入出差预计费用"></el-input-number>
      </el-form-item>
      <el-form-item label="请输入出差原因">
        <el-input type="textarea" v-model="form.objective" placeholder="请输入出差原因"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">申请</el-button>
        <el-button>取消</el-button>
      </el-form-item>
    </el-form>


  </div>
</template>

<script>
import { addEvection } from "@/api/system/evection";

export default {
  name: "Evection",
  dicts: ['ask_leave'],
  data() {
    return {
      form: {
        cost:0
      }
    }
  },
  created() {
    // this.getList();
  },
  methods: {
    onSubmit() {
      addEvection(this.form).then(response => {
        this.$modal.msgSuccess("新增成功");
        this.reset();
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        startDate: null,
        endDate: null,
        target: null,
        objective: null,
        cost: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateEvection(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addEvection(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },

  }
};
</script>
